package spike.db;
 
import java.sql.Connection;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.sql.Statement;

public class QueryPool {
	Statement stat = null;
	ResultSet rs = null;
	
	public void getSelectTwitter() throws ClassNotFoundException, SQLException {
		Connector.getInstance();
		Connection conn = Connector.getConnection();
		stat = conn.createStatement();
		rs = stat.executeQuery("Select * from twitter");

		while ( rs.next() ) {
			System.out.println(rs.getString(1) + "|" + rs.getString(2));
		}
		
		conn.close();
	}
	
	public void insertTwitter(String time, String message) throws ClassNotFoundException, SQLException {	
		Connector.getInstance();
		Connection conn = Connector.getConnection();
		message = message.replaceAll("'","-");
		stat = conn.createStatement();
		System.out.println("time : " + time + "   message : " + message);
		stat.executeUpdate("insert into twitter values ( '" + time 
						   + "', '" + message + "' );");
		conn.close();
	}
	
	public void deleteTwitter() throws ClassNotFoundException, SQLException {	
		Connector.getInstance();
		Connection conn = Connector.getConnection();
		stat = conn.createStatement();
		stat.executeUpdate("delete from twitter;");
		conn.close();
	}
	
}
